# 测试存储成序列化数据
import pickle
# 按顺序dump三组数据，load的时候会依次取出
# a1 = 'apple'  
# b1 = {1: 'One', 2: 'Two', 3: 'Three'}  
# c1 = ['fee', 'fie', 'foe', 'fum']  
# f1 = open('./temp.pkl', 'wb')  
# pickle.dump(a1, f1, True)  
# pickle.dump(b1, f1, True)  
# pickle.dump(c1, f1, True)  
# f1.close()  
# f2 = open('./temp.pkl', 'rb')  
# a2 = pickle.load(f2)  
# print(a2)
# b2 = pickle.load(f2)  
# print(b2)  
# f2.close()  
# 把三组数据按数组的形式dump进去
a1 = 'apple'
b1 = {1: 'One', 2: 'Two', 3: 'Three'}
c1 = ['fee', 'fie', 'foe', 'fum']
pickle.dump([a1, b1, c1],open('./temp2.pkl','wb'))
data = pickle.load(open('./temp2.pkl','rb'))
print(data[1])
#数组与单个按不同顺序放进去，挨个dump,挨个load
a1 = 'apple'  
b1 = {1: 'One', 2: 'Two', 3: 'Three'}  
c1 = ['fee', 'fie', 'foe', 'fum']
f2 = open('./temp2.pkl', 'wb')
pickle.dump([a1,b1],f2,True)
pickle.dump(c1,f2,True)
f2.close()
f3 = open('./temp2.pkl','rb')
data = pickle.load(f3)
print(data)
data2 = pickle.load(f3)
print(data2)